//
// Created by 原帅 on 2021/2/13.
//

#ifndef IVENGINE_IERUNLOOPTASKREPO_H
#define IVENGINE_IERUNLOOPTASKREPO_H

#include <map>
#include <IERunLoopInterface.h>

#define RUNLOOPREPO_ADDTASK(_repoId,_taskIF) \
        IERunloopTaskRepo::Singelton()->addTaskToRepo(_repoId,new _taskIF());

#define SCHEDULE_ONCETASK(_repoId) \
        IERunloopTaskRepo::Singelton()->scheduleTaskOnce(_repoId);

#define SCHEDULE_RUNLOOPTASK(_repoId) \
        IERunloopTaskRepo::Singelton()->scheduleTaskInRunloop(_repoId);


using namespace std;

class IERunloopTaskRepo {
public:
    class Builder {
    public:
        explicit Builder();
    };
private:
    static IERunloopTaskRepo* ieRunloopTaskRepo;
    explicit IERunloopTaskRepo();
    virtual ~IERunloopTaskRepo();

    map<unsigned long ,IERunLoopInterface*> taskRepoMap;

public:
    static IERunloopTaskRepo* Singelton();

    void addTaskToRepo(unsigned long repoid, IERunLoopInterface* anInterface);

    IERunLoopInterface* getTaskFromRepo(unsigned long repoid);

    void scheduleTaskInRunloop(unsigned long repoid);

    void scheduleTaskOnce(unsigned long repoid);

    void removeTaskFromRunloop(unsigned long repoid);


};


#endif //IVENGINE_IERUNLOOPTASKREPO_H
